﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var _State = "", Type = "";
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();       
        GetTree();
        GetGrid();
    }) 
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 181.5);

            }, 200);
            e.stopPropagation();

        });
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",           
            description: "==请选择所属机构==",
            height: "250px",
            click: function (data) {
                _organizeid = data.id;
                SearchEvent();
            }
        });
        $("#OrganizeId").ComboBoxTreeSetValue(_organizeid);
        //初始化时间
        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");

        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            description: "=选择=",
            click: function (item) { 
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);

    }

    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../QualificationManage/SearchRoom/GetBillStateTreeJson",
            onnodeclick: function (item) {
                switch (item.id) {
                    case "All":
                        _State = -1;
                        break;
                    case "CheckPassed":
                        _State = -2;
                        break;
                    case "Canceled":
                        _State = 4;
                        break;
                    case "CheckRejected":
                        _State = 5;
                        break;
                    case "WaitingCheck":
                        _State = 1;
                        break;
                    case "WaitingSearch":
                        _State = 2;
                        break;
                    case "Searched":
                        _State = 3;
                        break;  
                    default: break;
                }

                SearchEvent();
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }

    function GetGrid() {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable");
        var queryJson = {
            State: _State,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val()+" 23:59:59",
            OrganizeId: _organizeid
        };
        $gridTable.jqGrid({
            url: "../../QualificationManage/SearchRoom/GetPagList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            sortable: true,
            colModel: [
                { label: "主键", name: "id", hidden: true },
                { label: "申请人", name: "name", index: "names", width: 200, align: "center", sortable: false },
                { label: "手机号", name: "phone", index: "phone", width: 200, align: "center", sortable: false },
                {
                    label: "性别", name: "sex", index: "sex", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        if (cellvalue == 1) {
                            return "男";
                        }
                        return "女";
                    }
                },
                { label: "单据编号", name: "billcode", index: "billcode", width: 300, align: "center", sortable: false, },
                { label: "看房地址", name: "allname", index: "allname", width: 400, align: "left", sortable: false, },
                { label: "单据日期", name: "date", index: "date", width: 200, align: "center", sortable: false, },
               
                {
                     label: "状态", name: "state", index: "state", width: 200, align: "center", sortable: false,
                     formatter: function (cellvalue, options, rowObject) {
                         var Msg = "";
                         switch (cellvalue) {
                             case 1: Msg = "<span  style='background-color:#FFA07B' class='label'>待审批</span>";
                                 break;
                             case 2: Msg = "<span  style='background-color:#B9C46F' class='label '>未完成</span>";
                                 break; 
                             case 3: Msg = "<span  style='background-color:#4BC152' class='label '>已完成</span>";
                                 break;
                             case 4: Msg = "<span  style='background-color:#D9D6CF' class='label '>已取消</span>";
                                 break;
                             case 5: Msg = "<span  style='background-color:#D15252' class='label '>审批未通过</span>";
                                 break; 
                             default: Msg = "---";
                                 break;
                         }
                         return Msg;
                     }
                 },
                  
                { label: "预约看房时间", name: "expecttime", index: "expecttime", width: 200, align: "center", sortable: false },
                { label: "实际带看人", name: "realman", index: "realman", width: 200, align: "center", sortable: false },
                { label: "看房情况", name: "seeroominfo", index: "seeroominfo", width: 200, align: "center", sortable: false },

            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $('#btn_Reset').trigger("click");
            $(".ui-filter-text").trigger("click");
        }); 
    }
    function SearchEvent()
    {
        //查询事件 
            var queryJson = {
                State: _State,
                StartTime: $("#StartTime").val(),
                EndTime: $("#EndTime").val()+" 23:59:59",
                OrganizeId: _organizeid
            };
            $("#gridTable").jqGrid('setGridParam', {
                url: "../../QualificationManage/SearchRoom/GetPagList",
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        
       
    }
    function btn_detail() {
        var keyValue = $("#gridTable").jqGridRowValue("billcode");
         if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '单据详情(看房申请单)',
                url: '/QualificationManage/SearchRoom/Form?keyValue=' + keyValue,
                width: "1200px",
                height: "800px",
                btn: null,
                callBack: function (iframeId) { 
                }
            });
        }

    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">单据状态</div>
            <div id="itemTree1">
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search ">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 5px;"><div style="width:180px;" id="OrganizeId" type="selectTree" class="ui-select"></div></td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr> 
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                        </tr>

                    </table>

                </div>

                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default " onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default " onclick="btn_detail()"><i class="fa fa-eye"></i>&nbsp;查看</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>


            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>

        </div>
    </div>
</div>



